package com.ecoolex.chinadutyfree.retailer.job.scheduler;

import java.time.Instant;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.ecoolex.chinadutyfree.retailer.core.manager.CouponManager;
import com.ecoolex.chinadutyfree.retailer.entity.Coupon;
import com.ecoolex.framework.scheduler.Job;
import com.ecoolex.framework.scheduler.JobComponent;

@JobComponent
public class CouponExpireCheckJob {

	@Autowired
	private CouponManager couponManager;
	
	@Job(name = "chinadutyfree.CouponExpireCheckJob.checkStatus", describe = "检查商户优惠券过期状态")
	public void check() {
		List<Coupon> couponList = couponManager.getExpireCoupon(Date.from(Instant.now()),10);
		couponList.forEach(coupon -> {
			couponManager.expireCoupon(coupon, CouponExpireCheckJob.class.getSimpleName());
		});
	}
}
